<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends CI_Controller {

	protected $_view_data;

	function __construct() {
		parent::__construct();
		$lang = $this->input->get('lang');
		if (empty($lang)) {
			$lang = $this->uri->segment(1);
		}
        //默认语言为英语english
		if ($lang == 'cn') {
			$this->config->set_item('language', $lang);
			$this->lang->load('web', 'chinese');
		} else {
			$this->lang->load('web', 'english');
		}

		$this->load->helper('language');
		$this->_set_view_data();
	}

	private function _set_view_data() {
		if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
			$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,4);
			if (preg_match("/zh-c/i", $lang))
				$current_lang = '语言';
			else
				$current_lang = 'Language';
		} else {
			$current_lang = 'Language';
		}
		$this->_view_data['lang'] = $this->config->item('language');
		$this->_view_data['current_lang'] = $current_lang;
		$this->_view_data['html_lang'] = $this->lang->line('html_lang');
		
	}
	
}
